package com.isoft.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.stereotype.Component;

import lombok.Data;

/**
 * Created by yigeyanse on 2017/6/16.
 */
@Data
@Entity
@Table(name = "sys_role")
public class SysRole implements Serializable{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy= GenerationType.AUTO)
    private Integer sysRoleId;
	
	@Column
    private String sysRoleName;
	
	@Column
	private String sysUserDesc; // 密码;
	
	@Column
	private Boolean isAvailable = Boolean.FALSE; //是否可用,如果不可用将不会添加给用户
    
	// 角色 -- 权限关系：多对多关系;  
    @ManyToMany(fetch = FetchType.EAGER)  
    @JoinTable(name = "SysRolePermission", joinColumns = { @JoinColumn(name = "roleId") }, inverseJoinColumns = {  
            @JoinColumn(name = "permissionId") })  
    private List<SysPermission> permissionList;  
  
    // 用户 - 角色关系定义;  
    @ManyToMany  
    @JoinTable(name = "SysUserRole", joinColumns = { @JoinColumn(name = "roleId") }, inverseJoinColumns = {  
            @JoinColumn(name = "userId") })  
    private List<SysUser> userList;// 一个角色对应多个用户 

	@Override
	public String toString() {
		return "SysRole [sysRoleId=" + sysRoleId + ", sysRoleName=" + sysRoleName + ", sysUserDesc=" + sysUserDesc + ", isAvailable=" + isAvailable + "]";
	}


}
